package com.hzdl.cinema.Service.impl;

import com.hzdl.cinema.Service.SearchSeatService;
import com.hzdl.cinema.dao.SearchSeatDao;
import com.hzdl.cinema.dao.impl.SearchSeatDaoImpl;
import com.hzdl.cinema.domain.Play;
import com.hzdl.cinema.domain.Ticket;

import java.util.List;

public class SearchSeatServiceImpl implements SearchSeatService {
    SearchSeatDao searchSeatDao = new SearchSeatDaoImpl();

    //买票
    @Override
    public Ticket buyTickets(String playName) {
        List<Ticket> ticketList = searchSeatDao.buyTickets(playName);
        //如果票状态是0 就可以买
        for (Ticket ticket : ticketList) {
            if (ticket.getTicketStatus() == 0) {
               Play play= searchSeatDao.findPlay(playName);
                ticket.setPlay(play);
                return ticket;

            }
        }
        return null;
    }

    //确认购票
    @Override
    public void confirm(int userId, String ticketId) {
        searchSeatDao.confirm(userId,ticketId);
    }
}
